package com.devicemantra.coordinate.dataobjects;
import javax.jdo.annotations.*;


import java.util.*;

import com.devicemantra.coordinate.exceptions.operations.CException;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable ="true")
public class CGroup 
{
	@PrimaryKey
    @Persistent  //(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key mGroupKey;
	
	
	@Persistent(defaultFetchGroup="true")
	private String mGroupName;
	
	@Persistent
	private HashSet<String> mLocationList = new HashSet<String>();
	
	public CGroup(String pGroupName) {
		mGroupName = pGroupName;
	}
	
	public CGroup(String pGroupName,List<String> pLocationIdList) {
		mGroupName = pGroupName;
		mLocationList = new HashSet<String>(pLocationIdList);
	}
	
	/**
	 * @return the mGroupKey
	 */
	public Key getGroupKey() {
		return mGroupKey;
	}

	/**
	 * @param mGroupKey the mGroupKey to set
	 */
	public void setGroupKey(Key mGroupKey) {
		this.mGroupKey = mGroupKey;
	}

	
	public void addLocation(String pLocationId) {
		boolean lDoesItAlreadyExist = mLocationList.add(pLocationId);
		System.out.println("The element was part of the HashSet ? [" + !lDoesItAlreadyExist + "]");
	}
	
	public void addLocations(List<String> pLocationIdList)  {
		Iterator<String> lListIterator = pLocationIdList.iterator();
		while(lListIterator.hasNext()) {
			String lLocationId = lListIterator.next();
			addLocation(lLocationId);
		}
	}
	
	
}
